package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.Reply;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReplyMapper extends BaseMapper<Reply> {

    // 创建新的回复记录，无需提供r_id，由数据库自动生成
    @Insert("INSERT INTO reply (cmt_id, s_id, r_content, r_time, r_likes) " +
            "VALUES (#{cmtID}, #{sID}, #{rContent}, #{rTime}, #{rLikes})")
    void insertReply(Reply reply);

    // 根据r_id查找回复记录
    @Select("SELECT * FROM reply WHERE cmt_id = #{cmtID}")
    List<Reply> selectByCmtId(@Param("cmtID") int cmtID);

    // 根据r_id查找回复记录
    @Select("SELECT * FROM reply WHERE r_id = #{rID}")
    Reply selectByRId(@Param("rID") int rID);

    // 删除指定r_id的回复记录
    @Delete("DELETE FROM reply WHERE r_id = #{rID}")
    int deleteByRId(@Param("rID") int rID);

    // 更新回复记录
    @Update("UPDATE reply SET cmt_id = #{cmtID}, s_id = #{sID}, r_content = #{rContent}, " +
            "r_time = #{rTime}, r_likes = #{rLikes} WHERE r_id = #{rID}")
    int updateReply(Reply reply);
}
